<?php

namespace MoChat\App\Call\Action\Dashboard\CallOmission;


use MoChat\App\Call\Model\CallPlanWorkContact;
use MoChat\App\Call\Service\CallPlanService;
use MoChat\App\Call\Service\CallPlanWorkContactService;
use MoChat\App\Sales\Contract\SalesTaskContract;
use MoChat\Framework\Action\AbstractAction;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;
use MoChat\Framework\Request\ValidateSceneTrait;

/**
 * 呼叫任务批量转移
 * @Controller
 */
class Create extends AbstractAction
{
    use ValidateSceneTrait;

    /**
     * @Inject
     * @var CallPlanWorkContactService
     */
    protected $callPlanWorkContactService;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class),
     * })
     * @RequestMapping(path="/dashboard/callOmission/create", methods="POST")
     */
    public function handle()
    {
        $user = user();
        // 判断用户绑定企业信息
        if (!isset($user['corpIds']) || count($user['corpIds']) !== 1) {
            throw new CommonException(ErrorCode::INVALID_PARAMS, '未选择登录企业，不可操作');
        }
        $data = $this->request->all();

        $this->validated($data);
         $this->callPlanWorkContactService->transferTask($data);
         return [];
    }

    /**
     * 验证规则.
     */
    protected function rules(): array
    {
        return [
            'ids' => 'required',
            'callPlanId' => 'required|integer',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息.
     */
    protected function messages(): array
    {
        return [
            'ids.required' => 'id必选',
            'callPlanId.required' => '呼叫计划id必选',
            'callPlanId.integer' => '呼叫计划id参数错误',
        ];
    }
}